package cn.likun.kit;
/**
 * 
 *<p>html特殊字符转换工具</p>
 */
public class HtmlEncode {

	/**
	 * <p>编码特殊字符</p>
	 * @param value
	 * @return
	 */
	public static String encode(String value) {
		return value.replaceAll("<", "&lt;")
				.replaceAll(">", "&gt;")
				.replaceAll("&", "&amp;")
				.replaceAll("\"", "&quot;")
				.replaceAll("'", "&quot;")
				.replaceAll(new String(new byte[] {13}), "<br />")
				.replaceAll(new String(new byte[] {32}), " &nbsp;");
	}
	/**
	 * <p>反编码特殊字符</p>
	 * @param value
	 * @return
	 */
	public static String decode(String value) {
		return value.replaceAll("&lt;", "<")
				.replaceAll("&gt;", ">")
				.replaceAll("&amp;", "&")
				.replaceAll("&quot;", "\"");
	}
}
